package com.wly.network.packet
{
	import flash.utils.getDefinitionByName;
	import flash.utils.ByteArray;
	/**
	 * @author Administrator
	 */
	public class SCPacketPool
	{
		static private var _instance:SCPacketPool;
		
		static private var _pkgArr:Array;
		
		static public function getInstance():SCPacketPool
		{
			if(!_instance)
			{
				_instance = new SCPacketPool();
			}
			
			return _instance;
		}
		
		private function initPkgPool():void
		{
			_pkgArr = [];
		}
		
		public function onGetData(byteArr:ByteArray):void
		{
			if(!byteArr)
			{
				return;
			}
			
			var pktId:int = byteArr.readInt();
			var className:String = _pkgArr[pktId] as String;
			if(!className)
			{
				return;
			}
			
			var cls:Class = getDefinitionByName(className) as Class;
			var scPkt:SCPacket = new cls as SCPacket;
			if(scPkt)
			{
				scPkt.unSerialization(byteArr);
				scPkt.processPkt();
			}
		}
	}
}
